package easy;

public class Solution_278 extends VersionControl {

    public static int firstBadVersion(int n) {
        int begin = 1, end = n;
        while (true) {
            if (begin == end) {
                return isBadVersion(end)?end:end+1;
            }
            int middle = begin + (end - begin + 1)/2;
            boolean middleVersion = isBadVersion(middle);
            if (middleVersion) {
                end = middle-1;
            } else {
                begin = middle;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(firstBadVersion(2126753390));
    }
}

class VersionControl{
    public static boolean isBadVersion(int version) {
        if (version<1702766719) {
            return false;
        }
        return true;
    }
}
